package edu.hitsz.aircraft.shoot;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.HeroAircraft;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;
import edu.hitsz.bullet.HeroBullet;

import java.util.LinkedList;
import java.util.List;

/**
 * @author CsCN
 * 双向斜射
 * /// \\\
 */
public class SkewShoot implements ShootStrategy {

    @Override
    public List<BaseBullet> shoot(AbstractAircraft air) {
        List<BaseBullet> res = new LinkedList<>();
        int direction = air.getShootDirection();
        // 只射偶数, 一次射两个
        int shootNum = air.getShootNum() / 2;
        int x = air.getLocationX();
        int y = air.getLocationY() + direction * 2;
        int speedX = 3;
        int speedY = air.getSpeedY() + direction * 5;
        BaseBullet baseBullet;
        if (air instanceof HeroAircraft) {
            for (int i = 0; i < shootNum; i++) {
                baseBullet = new HeroBullet(x + (i * 2) * 10, y, -speedX, speedY, air.getPower());
                baseBullet = new HeroBullet(x - (i * 2) * 10, y, speedX, speedY, air.getPower());
                res.add(baseBullet);
            }
        } else {
            for (int i = 0; i < shootNum; i++) {
                baseBullet = new EnemyBullet(x + (i * 2) * 10 + 50, y, -speedX, speedY, air.getPower());
                res.add(baseBullet);
                baseBullet = new EnemyBullet(x - (i * 2) * 10 - 50, y, speedX, speedY, air.getPower());
                res.add(baseBullet);
            }
        }
        return res;
    }
}
